package components
{
	import camo.core.display.CamoDisplay;
	import flash.errors.IllegalOperationError;
	import camo.core.property.PropertySelector;
	import managers.GlobalPropertySheetManager;

	public class AbstractComponent extends CamoDisplay
	{	
		protected var defaultSelectorNames : Array;
		protected static const ID_DELIMITER : String = " ";
		
		public function AbstractComponent(self : AbstractComponent, id : String)  
        {  
            if(self != this)  
            {  
                //only a subclass can pass a valid reference to self  
                throw new IllegalOperationError( "Abstract class did not receive reference to self. " + className + " cannot be instantiated directly." );  
            }  
            else  
            {  
                parseStyleNames(id);  
                init( );  
            }
        }
        protected function parseStyleNames(id : String) : void  
        {  
            //trace(id);trace(this.id);
            defaultSelectorNames = id.split(ID_DELIMITER);  
            this.id = defaultSelectorNames.pop( );  
            // clean up selectors  
            defaultSelectorNames.unshift( "." + className );  
            defaultSelectorNames.push( "#" + this.id );
            //trace(defaultSelectorNames);  
        }
        protected function init() : void  
        {  
        	//trace(GlobalPropertySheetManager.instance.getSelector.apply( null, defaultSelectorNames));
            var prop : PropertySelector = GlobalPropertySheetManager.instance.getSelector.apply( null, defaultSelectorNames );  

            applyProperties( prop );  
        }
	}
}